import request from '@/utils/request'

// 查询单开发列表
export function listOnlCgformHead(query) {
  return request({
    url: '/head/onlCgformHead/list',
    method: 'get',
    params: query
  })
}

// 查询单开发详细
export function getOnlCgformHead(id) {
  return request({
    url: '/head/onlCgformHead/' + id,
    method: 'get'
  })
}

// 保存单开发
export function saveOnlCgformHead(data) {
  return request({
    url: '/head/onlCgformHead/save',
    method: 'post',
    data: data
  })
}

// 删除单开发
export function delOnlCgformHead(id) {
  return request({
    url: '/head/onlCgformHead/' + id,
    method: 'delete'
  })
}

// 导出单开发
export function exportOnlCgformHead(query) {
  return request({
    url: '/head/onlCgformHead/export',
    method: 'get',
    params: query
  })
}

// 保存单开发
export function saveAll(url, data) {
  return request({
    url,
    method: 'post',
    data: data
  })
}
// 同步表单开发
export function syncDb(id) {
  return request({
    url: '/head/onlCgformHead/api/doDbSynch?id=' + id,
    method: 'GET'
  })
}
// 删除表单开发
export function delDb(id, status) {
  return request({
    url: '/head/onlCgformHead/api/doDBdropTable/' + id + '/' + status,
    method: 'Delete'
  })
}
// 查询表单开发详细
export function delDbDetails(id) {
  return request({
    url: '/head/onlCgformHead/api/doTableDetails/' + id,
    method: 'GET'
  })
}
// 公共RestFul请求方法
export function requestAll(url, method) {
  return request({
    url,
    method: method || 'get'
  })
}
// 公共请求方法
export function requestMethod(url, method, data) {
  return request({
    url,
    method: method || 'get',
    data
  })
}
// get请求
export function getRequest(url, parameter) {
  return request({
    url: url,
    method: 'get',
    params: parameter
  })
}
// 保存菜单
export function saveMenu(data, headId, pathId) {
  return request({
    url: '/head/OnlineApiTest/api/saveMenu/' + headId + '/' + pathId,
    method: 'post',
    data: data
  })
}
// 查询主表配置字段
export function queryMasterTable(name) {
  return request({
    url: '/head/onlCgformHead/api/queryMasterTable?name=' + name,
    method: 'get'
  })
}

// 删除表单字段
export function delDbField(id) {
  return request({
    url: '/head/onlCgformHead/api/delDbField/' + id,
    method: 'Delete'
  })
}
// 导出列表
export function exportOnlineList(query) {
  return request({
    url: '/head/OnlineApiTest/api/exportOnlineList',
    method: 'get',
    params: query
  })
}
// 导出列表
export function queryNameByType(type, id) {
  return request({
    url: '/head/onlCgformHead/api/queryNameByType?type=' + type + '&id=' + id,
    method: 'get'
  })
}

// 导出列表
export function convertPinying(val) {
  return request({
    url: '/head/onlCgformHead/api/convertPinying?str=' + val,
    method: 'get'
  })
}

// 数据集列表
export function getDataSetList() {
  return request({
    url: '/head/onlCgformHead/api/getDataSetList',
    method: 'get'
  })
}
// 数据集列表
export function getOnlineTemplate(id) {
  return request({
    url: '/head/onlCgformHead/api/onlineTemplate?headId=' + id,
    method: 'get'
  })
}

// 导入表
export function importTable(data) {
  return request({
    url: '/head/onlCgformHead/importTable',
    method: 'post',
    params: data
  })
}

// 查询历史版本sql列表
export function listOnlCgformHeadRecord(query) {
  return request({
    url: '/record/onlCgformHeadRecord/list',
    method: 'get',
    params: query
  })
}

export function deleteByTableName(tableName) {
  return request({
    url: '/head/onlCgformHead/api/deleteByTableName/' + tableName,
    method: 'delete'
  })
}
// 主表移除关联子表
export function removeTableByName(tableName, headId) {
  return request({
    url: '/head/onlCgformHead/api/removeTableByName/' + tableName + '/' + headId,
    method: 'get'
  })
}
// 根据表明获取信息
export function getTableInfoByName(tableName) {
  return request({
    url: '/head/onlCgformHead/api/getTableInfoByName/' + tableName,
    method: 'get'
  })
}
// 根据表明获取信息
export function updateTableInfoByName(data) {
  return request({
    url: '/head/onlCgformHead/api/updateTableInfoByName',
    method: 'post',
    data: data
  })
}

// 根据id获取当前表字段
export function getCurrFields(headId) {
  return request({
    url: '/head/onlCgformHead/api/getCurrFields/' + headId,
    method: 'get'
  })
}
// 导出行数据
export function exportDataToJsonFile(query) {
  return request({
    url: '/head/onlCgformHead/api/exportDataToJson/' + query,
    method: 'get'
  })
}

export function findFieldByHeadId(query) {
  return request({
    url: '/head/onlCgformHead/findFieldByHeadId?headId=' + query,
    method: 'get'
  })
}

export function saveAutoPage(data) {
  return request({
    url: '/page/onlCgformAuthPage/saveAuthPage',
    method: 'post',
    data: data
  })
}
// 查询授权字段
export function findAuthField(query) {
  return request({
    url: '/head/onlCgformHead/findAuthField?headId=' + query,
    method: 'get'
  })
}

// 查询角色授权字段
export function getRoleAuthField(data) {
  return request({
    url: '/relation/onlCgformAuthRelation/getRoleAuthField',
    method: 'get',
    params: data
  })
}
export function saveRoleFieldAuth(data) {
  return request({
    url: '/relation/onlCgformAuthRelation/saveRoleFieldAuth',
    method: 'post',
    data: data
  })
}
/**
 * 为多个角色分配字段权限
 * @param {*} data
 * @returns
 */
export function saveMultipleRoleFieldAuth(data) {
  return request({
    url: '/relation/onlCgformAuthRelation/saveMultipleRoleFieldAuth',
    method: 'post',
    data: data
  })
}

// 生成代码
export function generateTest(data) {
  return request({
    url: '/onlGenerate/generateTest?headId=' + data,
    method: 'get'
  })
}

// 查询系统通知模板
export function findMsgTemplate() {
  return request({
    url: '/head/onlCgformHead/api/findMsgTemplate',
    method: 'get'
  })
}
// 新增事件详细配置
export function saveEventHandler(data) {
  return request({
    url: '/head/onlCgformHead/saveEventHandler',
    method: 'post',
    data: data
  })
}
// 查询事件详细配置
export function getEventHandlerByIdAndEventName(event, fieldId) {
  return request({
    url: `/head/onlCgformHead/getEventHandlerByIdAndEventName/${event}/${fieldId}`,
    method: 'get'
  })
}

// 更改同步状态
export function updateHeadSyncStatus(id) {
  return request({
    url: '/head/onlCgformHead/api/updateHeadSyncStatus?id=' + id,
    method: 'get'
  })
}
// 删除表单字段
export function delDbFieldIds(id) {
  return request({
    url: '/head/onlCgformHead/api/delDbFieldIds?ids=' + id,
    method: 'Delete'
  })
}
// 更改同步状态
export function queryFormEvent(id) {
  return request({
    url: '/head/onlCgformHead/queryFormEvent/' + id,
    method: 'get'
  })
}
// 排序字段
export function saveSort(data) {
  return request({
    url: '/head/onlCgformHead/api/saveSort',
    method: 'post',
    data: data
  })
}
// // 排序字段
// export function saveSort(data) {
//   return request({
//     url: '/head/onlCgformHead/api/saveSort',
//     method: 'post',
//     data: data
//   })
// }

// 获取选填附件下拉框数据
export function getDirByBelong(belong) {
  return request({
    url: '/head/onlCgformHead/getDirByBelong/' + belong,
    method: 'get'
  })
}
